<?php
$get_order = $this->get('order');
?>
<div class="sbar fixed">
    <div class="oneLayer">
        <div class="inner">
            <a href="/" class="home">
                <i class="icon-home icon-2x key"></i>
            </a>
            <a href="javascript:;" class="select">
                <i class="icon-search icon-2x key" onclick="searchGoods()" style="font-size: 18px;line-height: 25px;"></i>
            </a>
            <div class="bar"><input type="text" id="keywords" placeholder="输入关键字" value=""></div>
        </div>
    </div>
    <div class="twoLayer">
        <div class="-w-fiex"><a class="<?php if($get_order==1):?>key<?php endif;?>" onclick="search_goods(1)" >综合</a></div>
        <div class="-w-fiex"><a class="<?php if($get_order==2):?>key<?php endif;?>" onclick="search_goods(2)" >销量</a></div>
        <div class="-w-fiex"><a class="<?php if($get_order==4):?>key<?php endif;?>" onclick="search_goods(4)" >价格</a></div>
    </div>
</div>
<div style="height:45px"></div>
<div class="swrap">
    <div class="goods_group cF" id="goods-group">
        <?php foreach($goods_list as $k=>$v):?>
            <div class="goods">
                <a href="<?=url('goods/detail',['id'=>$v['id']])?>">
                    <img src="<?=$v['pic']?>">
                    <p class="name myc"><?=$v['title']?></p>
                    <p class="price key">￥&nbsp;<?=$v['price']?></p>
                </a>
            </div>
        <?php endforeach;?>
    </div>
</div>
<div id="loading" class="loading hide" style="display: none;">亲，没有更多了！</div>
<script>
var page =1;
function searchGoods(){
    var keywords =document.getElementById('keywords').value;
    window.location.href = "<?=url('goods/lists',['keyword'=>'"+keywords+"'])?>";
}
function search_goods(value){
    var o = GetRequest();
    o.order = value;
    o.url  = '/goods/lists';
    window.location.href = createUrl(o);
}
//获取滚动条当前的位置
function getScrollTop() {
    var scrollTop = 0;
    if(document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    } else if(document.body) {
        scrollTop = document.body.scrollTop;
    }
    return scrollTop;
}

//获取当前可视范围的高度
function getClientHeight() {
    var clientHeight = 0;
    if(document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
    } else {
        clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
    }
    return clientHeight;
}

//获取文档完整的高度
function getScrollHeight() {
    return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}

//滚动事件触发
window.onscroll = function() {
    if(getScrollTop() + getClientHeight() == getScrollHeight()) {
        var o = GetRequest();
        page++;
        o.url  = '/goods/lists';
        o.page = page;
        var url = createUrl(o);
        $.ajax({
            url:url,
            method:"post",
            data:{'ajax':true},
            dataType:"json",
            success:function(res){
                if(res.data != ""){
                    $("#goods-group").append(res.data);
                }else{
                    $("#loading").show();
                }

            }
        })

    }
}
</script>
